From b495c13cd781c92eb85bfe8fc48b86fcbc106dd3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Fri, 8 Sep 2017 21:26:04 +0200 Subject: [PATCH] babl: add rendering intent argument to icc loading API --- babl/babl-icc.c | 30 ++++++++++++++++++++++++++++++ babl/babl.h | 19 +++++++++++++++---- tools/babl-icc-rewrite.c | 2 +- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/babl/babl-icc.c b/babl/babl-icc.c index 7d79051..7b64732 100644 --- a/babl/babl-icc.c +++ b/babl/babl-icc.c @@ -671,6 +671,7 @@ static char *decode_string (ICC *state, const char *tag, const char *lang, const const Babl * babl_space_from_icc (const char *icc_data, int icc_length, + BablIccIntent intent, const char **error) { ICC *state = icc_state_new ((char*)icc_data, icc_length, 0); @@ -684,6 +685,7 @@ babl_space_from_icc (const char *icc_data, sign_t profile_class, color_space; + if (!error) error = &int_err; *error = NULL; @@ -710,6 +712,34 @@ babl_space_from_icc (const char *icc_data, } } + switch (intent) + { + case BABL_ICC_INTENT_RELATIVE_COLORIMETRIC: + /* that is what we do well */ + break; + case BABL_ICC_INTENT_PERCEPTUAL: + /* if there is an A2B0 and B2A0 tags, we do not do what that + * profile is capable of - since the CLUT code is work in progress + * not in git master yet. + */ + if (icc_tag (state, "A2B0", NULL, NULL) && + icc_tag (state, "B2A0", NULL, NULL)) + { + *error = "profile contains perceptual luts and perceptual was explicitly asked for, babl does not yet support CLUTs"; + } + else + { + intent = BABL_ICC_INTENT_RELATIVE_COLORIMETRIC; + } + break; + case BABL_ICC_INTENT_ABSOLUTE_COLORIMETRIC: + *error = "absolute colormetric not implemented"; + break; + case BABL_ICC_INTENT_SATURATION: + *error = "absolute stauration not supported"; + break; + } + { int offset, element_size; if (!*error && icc_tag (state, "rTRC", &offset, &element_size)) diff --git a/babl/babl.h b/babl/babl.h index 80f342b..a7d75b5 100644 --- a/babl/babl.h +++ b/babl/babl.h @@ -90,6 +90,13 @@ const Babl * babl_model (const char *name); */ const Babl * babl_space (const char *name); +typedef enum { + BABL_ICC_INTENT_PERCEPTUAL = 0, + BABL_ICC_INTENT_RELATIVE_COLORIMETRIC = 1, + BABL_ICC_INTENT_SATURATION = 2, + BABL_ICC_INTENT_ABSOLUTE_COLORIMETRIC = 3 +} BablIccIntent; + /** * babl_space_from_icc: * @@ -101,10 +108,12 @@ const Babl * babl_space (const char *name); * if an error occurs, NULL is returned and an error message * is provided in error. * - * Create a babl space from an in memory ICC profile, the - * profile does no longer need to be loaded for the space to work, - * multiple calls with the same icc profile and same icc_transform - * will result in the same space. + * Create a babl space from an in memory ICC profile, the profile does no + * longer need to be loaded for the space to work, multiple calls with the same + * icc profile and same intent will result in the same babl space. + * + * On a profile that doesn't contain A2B0 and B2A0 CLUTs perceptual and + * relative-colorimetric intents are treated the same. * * If a BablSpace cannot be created from the profile NULL is returned and a * static string is set on the const char *value pointed at with &value @@ -113,6 +122,7 @@ const Babl * babl_space (const char *name); */ const Babl *babl_space_from_icc (const char *icc_data, int icc_length, + BablIccIntent intent, const char **error); /* babl_icc_get_key: @@ -128,6 +138,7 @@ const Babl *babl_space_from_icc (const char *icc_data, * "copyright", "manufacturer", "device", "profile-class", "color-space" and * "pcs". */ + char *babl_icc_get_key (const char *icc_data, int icc_length, const char *key, diff --git a/tools/babl-icc-rewrite.c b/tools/babl-icc-rewrite.c index 0746d50..f30b20e 100644 --- a/tools/babl-icc-rewrite.c +++ b/tools/babl-icc-rewrite.c @@ -79,7 +79,7 @@ main (int argc, free (str); } } - babl = babl_space_from_icc (icc_data, icc_len, &error); + babl = babl_space_from_icc (icc_data, icc_len, 0, &error); free (icc_data); if (error || !babl) { -- 2.30.2